void get_ob_message(string filename, string ob1_path, string ob1_name, string ob2_path, string ob2_name, vector<string> A, vector<string> B);
void diff__cached();

void diff__cached()
{
    map<string, string> ma;  //暂存区文件名及其SHA1-ID
    map<string, string> mc;  //提交区文件名及其SHA1-ID
    index_file* fc = &fp;
    do{
        int i;
        if(fc->mode == 1)
        {    
            ma[fc->file_name] = "";
            for(i = 0; i < 40; i++)
            {    
                ma[fc->file_name].push_back((fc->SHA1_ID)[i]);        
            }
        }
        if(fc->mode == 2)
        {
            mc[fc->file_name] = "";
            for(i = 0; i < 40; i++)
                mc[fc->file_name].push_back((fc->SHA1_ID)[i]);
        }
        fc = fc->next;
    }
    while(fc != NULL);
    map<string, string>::iterator iter;
    iter = ma.begin();
    while (iter != ma.end())
    {
        string file_name = iter->first;
        string add_ID = ma[file_name];
        string commit_ID = mc[file_name];
        vector<string> A;
        vector<string> B;
        if(add_ID.size() == 40 && commit_ID.size() == 40)
            get_ob_message(file_name, add_ID.substr(0, 2), add_ID.substr(2, 40), commit_ID.substr(0, 2), commit_ID.substr(2, 40), A, B);
        vector<string> ().swap(A);
        vector<string> ().swap(B);
        iter++;   
    }
}

void get_ob_message(string filename, string ob1_path, string ob1_name, string ob2_path, string ob2_name, vector<string> A, vector<string> B)
{
    string s = is_win_os() ? "\\" : "/";
    string path = store_path() + s + ".git" + s + "objects" + s + ob1_path + s + ob1_name + ".bin";
    ifstream f1(path.c_str(), ios::binary);
    string line;
    while (getline(f1, line))
    {   
        A.push_back(line);
    }
    path = store_path() + s + ".git" + s + "objects" + s + ob2_path + s + ob2_name + ".bin";
    ifstream f2(path.c_str(), ios::binary);
    while (getline(f2, line))
    {   
        B.push_back(line);
    }
    int a = Mysers_diff(B, A, B.size(), A.size());
    cout << filename << "共出现" << a << "次修改" << endl;
}